/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.common.util;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.ce.pms.charge.service.IChargeStaService;
import com.ce.pms.charge.vo.ChargeStaVO;

/**
 * 功能描述：下拉框联动装配工具类<br>
 * @author 罗军林 创建日期：2008-8-21
 */
public class UnitedSelectUntil {

	/**
	 * 功能描述:根据指定ID找出其下拉框数据并装配成XML并向Response输出<br>
	 * @param response
	 * @param chargeStaService
	 * @param chargeItemId<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public static void loadOptionXML(HttpServletResponse response, IChargeStaService chargeStaService,Long chargeItemId)
	{
		response.setContentType("text/xml;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		String xmlStr = converToXML(chargeItemId,chargeStaService);
		try {
			byte[] bytes = xmlStr.getBytes("utf-8");
			response.getOutputStream().write(bytes);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String converToXML(Long chargeItemId, IChargeStaService chargeStaService)
	{
		StringBuffer xmlStr = new StringBuffer();
    	xmlStr.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
    	xmlStr.append("<select-list>");
		List<ChargeStaVO> chargeStaList = chargeStaService.queryAllChargeSatBy(chargeItemId);
		for(ChargeStaVO chargeSta : chargeStaList)
		{
	    		xmlStr.append("<select-node>");
	    		xmlStr.append("<option-text>" + chargeSta.getStaName() + "</option-text>");
	    		xmlStr.append("<option-id>"+chargeSta.getKeyword()+"</option-id>");
	    		xmlStr.append("</select-node>");
		}
		 xmlStr.append("</select-list>");
		 return xmlStr.toString();
	}

}
